﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using GreatB2C.Utility;
using GreatB2C.Config.Shop;

namespace GreatB2C.Web.Manage.SystemSet.Shop
{
    public partial class TemplateConfig : Inherit.ManagePage
    {
        protected void Page_Load( object sender , EventArgs e )
        {
            if ( !IsPostBack )
            {
                LoadSetting( );
            }
        }

        protected void LoadSetting( )
        {
            txtEmailOfOrderConfirm.Text =  StringHelper.XmlDecode( Config.Shop.TemplateConfig.EmailOfOrderConfirm.ToString( ) );
            txtEmailOfReceiptMoney.Text = StringHelper.XmlDecode( Config.Shop.TemplateConfig.EmailOfReceiptMoney.ToString( ) );
            txtEmailOfRefund.Text = StringHelper.XmlDecode( Config.Shop.TemplateConfig.EmailOfRefund.ToString( ) );
            txtEmailOfInvoice.Text = StringHelper.XmlDecode( Config.Shop.TemplateConfig.EmailOfInvoice.ToString( ) );
            txtEmailOfDeliver.Text = StringHelper.XmlDecode( Config.Shop.TemplateConfig.EmailOfDeliver.ToString( ) );
            txtEmailOfSendCard.Text = StringHelper.XmlDecode( Config.Shop.TemplateConfig.EmailOfSendCard.ToString( ) );
            txtEmailOfCouponMessage.Text = StringHelper.XmlDecode( Config.Shop.TemplateConfig.EmailOfCouponMessage.ToString( ) );
            txtEmailOfCouponInfosMessage.Text = StringHelper.XmlDecode( Config.Shop.TemplateConfig.EmailOfCouponInfosMessage.ToString( ) );
            txtOrderPrintFormat.Text = StringHelper.XmlDecode( Config.Shop.TemplateConfig.OrderPrintFormat.ToString( ) );
            txtConsignmentFormat.Text = StringHelper.XmlDecode( Config.Shop.TemplateConfig.ConsignmentFormat.ToString( ) );
            txtCreditOrderPrintFormat.Text = StringHelper.XmlDecode( Config.Shop.TemplateConfig.CreditOrderPrintFormat.ToString( ) );
            txtCreditConsignmentFormat.Text = StringHelper.XmlDecode( Config.Shop.TemplateConfig.CreditConsignmentFormat.ToString( ) );
            txtOutOfStockLog.Text = StringHelper.XmlDecode( Config.Shop.TemplateConfig.OutOfStockLog.ToString( ) );
            txtFillProduct.Text = StringHelper.XmlDecode( Config.Shop.TemplateConfig.FillProduct.ToString( ) );
        }

        protected void BtnSubmit_Click( object sender , EventArgs e )
        {
            bool isSuccess = Config.Shop.TemplateConfig.Config( StringHelper.XmlEncode( txtEmailOfOrderConfirm.Text.Trim( ) ) , StringHelper.XmlEncode( txtEmailOfReceiptMoney.Text.Trim( ) ) , StringHelper.XmlEncode( txtEmailOfRefund.Text.Trim( ) ) , StringHelper.XmlEncode( txtEmailOfInvoice.Text.Trim( ) )
            , StringHelper.XmlEncode( txtEmailOfDeliver.Text.Trim( ) ) , StringHelper.XmlEncode( txtEmailOfSendCard.Text.Trim( ) ) , StringHelper.XmlEncode( txtEmailOfCouponMessage.Text.Trim( ) ) , StringHelper.XmlEncode( txtEmailOfCouponInfosMessage.Text.Trim( ) )
            , StringHelper.XmlEncode( txtOrderPrintFormat.Text.Trim( ) ) , StringHelper.XmlEncode( txtConsignmentFormat.Text.Trim( ) ) , StringHelper.XmlEncode( txtCreditOrderPrintFormat.Text.Trim( ) ) , StringHelper.XmlEncode( txtCreditConsignmentFormat.Text.Trim( ) )
             , StringHelper.XmlEncode( txtOutOfStockLog.Text.Trim( ) ) , StringHelper.XmlEncode( txtFillProduct.Text.Trim( ) ) );

            if ( isSuccess )
            {
                Response.Redirect( "../../Message.aspx?msg=" + Server.UrlEncode( "网站信息配置成功！" ) + "&rtn=SystemSet/Shop/TemplateConfig.aspx" );
            }
            else
            {
                Response.Redirect( "../../Message.aspx?msg=" + Server.UrlEncode( "网站信息配置失败，请联系管理员！" ) + "&rtn=SystemSet/Shop/TemplateConfig.aspx" );
            }
        }
    }
}
